import express from 'express';
import { HealthDataController } from '@/controllers/HealthDataController';
import { AuthMiddleware } from '@/middleware/auth';
import { validateRequest, commonSchemas } from '@/middleware/validation';

const router = express.Router();
const healthDataController = new HealthDataController();

// 所有健康数据路由都需要身份验证
router.use(AuthMiddleware.authenticate);

/**
 * @route POST /api/v1/health/sync
 * @desc 同步健康数据
 * @access Private
 */
router.post('/sync',
  validateRequest({
    body: commonSchemas.healthDataSync
  }),
  healthDataController.syncHealthData
);

/**
 * @route POST /api/v1/health/sleep/sync
 * @desc 同步睡眠数据
 * @access Private
 */
router.post('/sleep/sync',
  validateRequest({
    body: commonSchemas.sleepDataSync
  }),
  healthDataController.syncSleepData
);

/**
 * @route POST /api/v1/health/batch-sync
 * @desc 批量同步健康数据
 * @access Private
 */
router.post('/batch-sync',
  healthDataController.batchSyncHealthData
);

/**
 * @route GET /api/v1/health/latest
 * @desc 获取最新健康数据
 * @access Private
 */
router.get('/latest',
  healthDataController.getLatestHealthData
);

/**
 * @route GET /api/v1/health/range
 * @desc 获取指定日期范围的健康数据
 * @access Private
 */
router.get('/range',
  validateRequest({
    query: commonSchemas.dateRange.keys({
      limit: commonSchemas.pagination.extract('limit')
    })
  }),
  healthDataController.getHealthDataByRange
);

/**
 * @route GET /api/v1/health/sleep/:date
 * @desc 获取指定日期的睡眠数据
 * @access Private
 */
router.get('/sleep/:date',
  validateRequest({
    params: {
      date: commonSchemas.dateString
    }
  }),
  healthDataController.getSleepData
);

/**
 * @route GET /api/v1/health/sleep/weekly
 * @desc 获取最近7天的睡眠数据
 * @access Private
 */
router.get('/sleep/weekly',
  healthDataController.getWeeklySleepData
);

/**
 * @route GET /api/v1/health/trends
 * @desc 获取健康趋势数据
 * @access Private
 */
router.get('/trends',
  validateRequest({
    query: {
      days: commonSchemas.daysCount.optional()
    }
  }),
  healthDataController.getHealthTrends
);

export default router;